package com.yaser.util;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
@Qualifier("messenger")
public class Messenger {

	/**
	 * 
	 * Adds message to {@link FacesContext} with {@link Severity} error
	 * 
	 * @param title
	 * 				title of the message
	 * @param summary
	 * 				explanation of the message
	 */
	public void facesErrorMsg(String title, String summary) {
		FacesContext.getCurrentInstance().
        addMessage(null, 
           new FacesMessage(FacesMessage.SEVERITY_ERROR, title,summary));

	}
	
	/**
	 * 
	 * Adds message to {@link FacesContext} with {@link Severity} error, just uses the title not uses summary
	 * 
	 * @param title
	 * 				title of the message
	 */
	public void facesErrorMsg(String title) {
		FacesContext.getCurrentInstance().
		addMessage(null, 
				new FacesMessage(FacesMessage.SEVERITY_ERROR, title,null));
		
	}
	
	/**
	 * 
	 * Adds message to {@link FacesContext} with {@link Severity} warning
	 * 
	 * @param title
	 * 				title of the message
	 * @param summary
	 * 				explanation of the message
	 */
	public void facesWrnMsg(String title, String summary) {
		FacesContext.getCurrentInstance().
		addMessage(null, 
				new FacesMessage(FacesMessage.SEVERITY_WARN, title,summary));
		
	}
	
	/**
	 * 
	 * Adds message to {@link FacesContext} with {@link Severity} warning, just uses the title not uses summary
	 * 
	 * @param title
	 * 				title of the message
	 */
	public void facesWrnMsg(String title) {
		FacesContext.getCurrentInstance().
		addMessage(null, 
				new FacesMessage(FacesMessage.SEVERITY_WARN, title,null));
		
	}
	/**
	 * 
	 * Adds message to {@link FacesContext} with {@link Severity} info
	 * 
	 * @param title
	 * 				title of the message
	 * @param summary
	 * 				explanation of the message
	 */
	public void facesInfoMsg(String title, String summary) {
		FacesContext.getCurrentInstance().
		addMessage(null, 
				new FacesMessage(FacesMessage.SEVERITY_INFO, title,summary));
		
	}
	
	/**
	 * 
	 * Adds message to {@link FacesContext} with {@link Severity} info, just uses the title not uses summary
	 * 
	 * @param title
	 * 				title of the message
	 */
	public void facesInfoMsg(String title) {
		FacesContext.getCurrentInstance().
		addMessage(null, 
				new FacesMessage(FacesMessage.SEVERITY_INFO, title,null));
		
	}
}
